package cn.edu.uibe.ui_demo.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.List;

import cn.edu.uibe.ui_demo.R;
import cn.edu.uibe.ui_demo.beans.Dish;
import cn.edu.uibe.ui_demo.retrofitservice.RetrofitService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private EditText editText4,editText3;
        private Button loginButton;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate( savedInstanceState );
            setContentView( R.layout.activity_main );
            loginButton=findViewById( R.id.button );
            loginButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    //启动界面
                    //    Intent intent=new Intent( );
                    //    intent.setClass( MainActivity.this,// RecyclerViewActivity.class
                    //           HomeActivity.class );
                    //  startActivity( intent );
                    //  finish();
                    Retrofit retrofit = new Retrofit.Builder()
                            .baseUrl( "http://172.17.7.95:8080/MenuAPIDemo/" )
                            .addConverterFactory( GsonConverterFactory.create() )
                            .build();

                    RetrofitService retrofitService = retrofit.create( RetrofitService.class );
                    Call<List<Dish>> dishesCall = retrofitService.getDishes();
                    dishesCall.enqueue(new Callback<List<Dish>>() {
                        @Override
                        //处理正常响应
                        public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
                            List<Dish> dishes = response.body();
                            Toast.makeText(MainActivity.this,"dishes"+dishes.size(),Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        //处理异常响应
                        public void onFailure(Call<List<Dish>> call, Throwable t) {
                            Toast.makeText(MainActivity.this,""+t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();

                        }
                    });
                }
            });
        }
}



